package com.shixj.ef.execute;

import com.shixj.ef.config.FetchConfig;
import com.shixj.ef.vo.FetchRequest;
import com.shixj.ef.vo.FetchResponse;
import com.shixj.ef.vo.FetchResult;
import org.apache.http.impl.client.CloseableHttpClient;

import java.util.List;
import java.util.concurrent.BlockingQueue;


/**
 * Created by shixj on 2017/9/19.
 */
public interface HttpFetchExecute {

    void sendFetch();

    /**
     * 阻塞队列获取返回结果
     * @return
     */
    FetchResult takeResult();

    /**
     * 添加爬虫结果至队列  阻塞
     * @param fetchResult
     */
    void putResult(FetchResult fetchResult) ;

    /**
     * 获取可用请求  阻塞take
     * @return
     */

    FetchRequest takeRequest();
    /**
     * 获取可用请求 非阻塞poll
     * @return
     */

    FetchRequest pollRequest();
    /**
     * 向对列添加可用请求   阻塞
     * @param fetchRequest
     */
    void putRequest(FetchRequest fetchRequest) ;
    /**
     * 获取可用响应 阻塞take
     * @return
     */
    FetchResponse takeResponse();
    /**
     * 获取可用响应 非阻塞poll
     * @return
     */
    FetchResponse pollResponse();
    /**
     * 获取可用响应 延迟设定
     * @return
     */
    FetchResponse pollResponse(Long timeDelay);
    /**
     * 向对列添加可用响应  阻塞
     * @param fetchResponse
     */
    void putResponse(FetchResponse fetchResponse) ;

    /**
     * 获取全部爬虫结果
     * @return
     */
    List<FetchResult> getFetchResults();


    /**
     * 添加爬虫结果至list
     * @return
     */
    void addFetchResult(FetchResult fetchResult);
    /**
     * 爬虫是否运行
     * @return
     */
    boolean isRun();

    /**
     * 是否停止爬虫
     * @param run
     */
    void setRun(boolean run);

    /**
     * 获取爬虫设置
     * @return
     */
    FetchConfig getConfig();

    /**
     * 设置HttpClient
     * @param httpClient
     */
    void setHttpClient(CloseableHttpClient httpClient) ;

}
